import { defineStore } from 'pinia';
import { ref,computed } from 'vue';
import axios from 'axios';
//导出一个store,他其实返回的是一个方法
export const useCounterStore = defineStore('counter',() => {
   //定义数据
    const count = ref(0);


    //定义修改数据的方法
    const increment = () => {
        count.value++;
    }

    //getters定义 Pina中的getters直接使用computed函数进行模拟
    const doubleCount = computed(() => {
        return count.value * 2;
    })

    //定义异步的action yarn add axios
    const API_URL = "https://api.apiopen.top/api/sentences";
    const name = ref();
    const getList = async () => {
        const result =  await axios.get(API_URL);
        name.value = result.data.result.name
        console.log(name.value);

    }

    //已对象的形式返回出去
    return {
        count,
        name,
        increment,
        doubleCount,
        getList, 
    }
})